package com.jzo2o.orders.manager.Handler.OrdersHandler;

import com.jzo2o.orders.base.model.domain.Orders;

import com.jzo2o.orders.manager.model.dto.request.PlaceOrderReqDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.List;

/**
 * 订单处理责任链管理器
 */
@Slf4j
@Component
public class    OrderHandlerChain {
    
    private final List<OrdersHandlerNew> handlers;
    
    /**
     * Spring会自动注入所有OrdersHandler的实现类
     */
    public OrderHandlerChain(List<OrdersHandlerNew> handlers) {
        // 按照order顺序排序
        this.handlers = handlers;
        log.info("订单责任链初始化完成，共{}个处理器", this.handlers.size());
    }
    
    /**
     * 执行责任链
     */
    public void execute(Orders order, PlaceOrderReqDTO reqDTO) {
        for (OrdersHandlerNew handler : handlers) {
            log.debug("执行处理器: {}", handler.getClass().getSimpleName());
            handler.process(order, reqDTO);
        }
        log.info("订单责任链执行完成");
    }
}